package com.asiainfo.complier.helper;

import java.util.ArrayList;

import com.asiainfo.complier.common.ComplierInfo;

public class ComplierErrorHelper {

	/**
	 * get Complier Info
	 * 
	 * @param name
	 * @param sourceCode
	 * @return
	 */
	public static ArrayList<ComplierInfo> getComplierInfo(String sName,
			String sourceCode) {

		ArrayList<ComplierInfo> infoList = new ArrayList<ComplierInfo>();
		if (sourceCode == null)
			return null;
		String[] lineList = sourceCode.split("\n");
		sName = sName + ":";
		for (String str : lineList) {

			int index = str.indexOf(sName);
			if (index != -1) {
				int ePos = str.indexOf(":", index + sName.length());
				if (ePos != -1) {
					int linenUumber = Integer.parseInt(str.substring(index
							+ sName.length(), ePos));
					String errorMessage = str.substring(ePos + 1);
					ComplierInfo info = new ComplierInfo();
					info.setErrorLine(linenUumber);
					info.setErrorMessage(errorMessage);
					infoList.add(info);
				}
			}

		}
		return infoList;

	}
}
